<template>

  <smart-page id="system-menu">
    <template #actions>
      <a-button @click="treePage.toggleTree()" v-text="toggleText"/>
      <a-button  v-auth="Acl.SYSTEM_ORG_DEPT_ADD" type="primary" @click="editCtr.open()">新建部门</a-button>

    </template>
    <a-table
        v-model:expandedKeys="expandedKeys"
        :table-layout-fixed="theme.layoutFixed"
        :columns="DEPT_COLUMNS"
        :row-key="rowKey"
        :column-resizable="theme.resizable"
        :bordered="theme.bordered"
        :stripe="theme.stripe"
        :sticky-header="theme.sticky"
        :hoverable="theme.hoverAble"
        :loading="theme.loading"
        :data="dataSource">


      <template #action="{ record }">
        <a-space size="mini">
          <a-link  v-auth="Acl.SYSTEM_ORG_DEPT_ADD" @click="editCtr.open({ organ:record.organ,  parentCode:record.code  })" v-text="'子部门'"/>
          <a-link v-auth="Acl.SYSTEM_ORG_DEPT_UPDATE"  @click="editCtr.open(record)" v-text="'修改'"/>
          <a-link  v-auth="Acl.SYSTEM_ORG_DEPT_DELETE" status="danger" @click="onDelete(record)"> 删除</a-link>
        </a-space>
      </template>
    </a-table>


    <EditModal v-if="editCtr.show" :record="editCtr.record" @cancel="editCtr.close"/>
  </smart-page>


</template>
<script lang="ts" setup name="system-organ-dept">
import {onMounted} from 'vue';
import {TreePage} from "@/libs/core";
import {DEPT_COLUMNS} from "../resource/colums";
import {SystemHttp} from "../resource/http";
import EditModal from './edit.vue'
import {Acl} from "@/libs/acl";

const {getDeptList, delDept} = SystemHttp
const pageConfig = {title: '部门', rowKey: 'id', nameKey: 'name'}

const treePage = new TreePage(pageConfig).setFetchXhr(getDeptList).setDeleteXhr(delDept)
    .setTreeMap("0", "code", "parentCode")
    .setPermission(Acl.SYSTEM_ORG_DEPT_LIST)


const {theme, rowKey, dataSource, editCtr, expandedKeys,} = treePage
const {onFetch, onDelete, toggleText} = treePage


onMounted(async () => {
  await onFetch()
  treePage.toggleTree()
})
</script>

<style lang="less" scoped>
:deep( .smart-page-header) {
  margin-bottom: 1px !important;
}
</style>